/*对于灯设备 小爱同学只支持以下语音指令:
  √ 打开/关闭{门口}的{灯}
    把{卧室}的{灯}调为{红色} 颜色范围为0-16777215(0xFFFFFF)
  √ 把{卧室}的{灯}的{亮度调高一点} 亮度范围为1-100
    把{门口}的{灯}的{色温}调到{1400} 色温范围为1000-10000
    把{卧室}的{灯}调为{月光模式}
  √ 查询{卧室}的{灯}的状态
*/

void init_moit_light()
{
    BlinkerMIOT.attachPowerState(miotPowerState); //电源类
    BlinkerMIOT.attachBrightness(miotBright);     //亮度
    BlinkerMIOT.attachQuery(miotQuery);           //查询接口
}

/**
  * @brief  小爱同学用户自定义电源类操作函数
  * @param  state:操作状态
  * @retval None
  */
void miotPowerState(const String &state)
{
    BLINKER_LOG("need set power state: ", state);

    button1_callback(state);
    if (state == BLINKER_CMD_ON)
    { //开灯
        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();
    }
    else if (state == BLINKER_CMD_OFF)
    {
        BlinkerMIOT.powerState("off");
        BlinkerMIOT.print();
    }
}

/**
  * @brief  小爱同学用户自定义亮度类操作函数
  * @param  bright:表示亮度数字的字符串
  * @retval None
  */
void miotBright(const String &bright)
{
    BLINKER_LOG("need set brightness: ", bright);

    wsState = true;
    light = bright.toInt();
    analogWrite(LED_BUILTIN, (100 - light) * 10);
    BlinkerMIOT.brightness(light);
    BlinkerMIOT.print();
}

/**
  * @brief  小爱同学用户自定义查询接口
  * @param  bright:表示亮度数字的字符串
  * @retval None
  */
void miotQuery(int32_t queryCode)
{
    BLINKER_LOG("MIOT Query codes: ", queryCode);

    switch (queryCode)
    {
    case BLINKER_CMD_QUERY_POWERSTATE_NUMBER: //目前对于灯只支持 电源状态
        BLINKER_LOG("MIOT Query Power State");
        BlinkerMIOT.powerState(wsState ? "on" : "off");
        BlinkerMIOT.print();
        break;
    default:
        BlinkerMIOT.powerState(wsState ? "on" : "off");
        BlinkerMIOT.color(0);
        BlinkerMIOT.mode(0);
        BlinkerMIOT.colorTemp(1000);
        BlinkerMIOT.brightness(1);
        BlinkerMIOT.print();
        break;
    }
}
